package cn.ex;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import java.util.List;

public class Ex8 {
    public static void main(String[] args) throws IOException {
// 编写双色球效果
      Random rand = new Random();
      // 生成蓝色 1 （1-16）
      int blue = rand.nextInt(16) + 1;

      // 生成红色 6 （1-33）
      Set<Integer> reds = new HashSet<>();
      while (reds.size() < 6)
        reds.add(rand.nextInt(33) + 1);
      System.out.println(reds);
      System.out.println(blue);
      List<Integer> list = new ArrayList<Integer>(reds);
      list.sort((a, b) -> a - b);
      list.add(blue);
      System.out.println(list);

      BufferedImage i = new BufferedImage(450, 100, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g = i.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);

      g.setFont(new Font("", Font.BOLD, 25));
      g.setStroke(new BasicStroke(3));
      for (int n = 0; n < list.size(); n++) {
        g.setColor(Color.BLUE);
        int x = n * 55 + 12;
        int y = 28;
        String sc = String.format("%02d", list.get(n));
        if (n <= 5) {
          g.setColor(Color.RED);
          g.drawOval(x, y, 50, 50);
          g.drawString(sc, x + 12, y + 33);
          continue;
        }
        g.drawOval(x, y, 50, 50);
        g.drawString(sc, x + 12, y + 33);

      }
      g.dispose();
      ImageIO.write(i, "png", new FileOutputStream("ok.png"));
    }
}
